package com.wyp168.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName BuildArraySolution
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/10/15 11:37
 */
public class BuildArraySolution {
    public static void main(String[] args) {
        BuildArraySolution solution = new BuildArraySolution();

        int[] target = {1,2,4};
        int n = 4;

        List<String> result = solution.buildArray(target, n);
        result.forEach(System.out::println);
    }

    public static final String PUSH = "Push";
    public static final String POP = "Pop";

    public List<String> buildArray(int[] target, int n) {
        List<String> resultList = new ArrayList<>();

        int num = 1;
        int i = 0;

        while (i < target.length && num <= n) {
            resultList.add(PUSH);

            if (target[i] != num) {
                resultList.add(POP);
                num ++;
                continue;
            }
            num ++;
            i ++;
        }
        return resultList;

    }
}
